package com.github.livebase.log;

import java.io.File;
import java.util.Date;

/**
 * @ClassName FileLog
 * @description:
 * @author: biao532
 * @create: 2024-02-02 12:08
 * @Version 1.0
 **/
public class FileLogger extends AbstractLogger {
    private String file;
    private FileRefresher writer;
    public FileLogger(File file, int level) {
        this(file.getAbsolutePath(), level);
    }
    public FileLogger(String file, int level) {
        this(FileRefresher.singleton(), file, level);
    }
    public FileLogger(Formatter formatter, String file, int level) {
        this(formatter, FileRefresher.singleton(), file, level);
    }
    public FileLogger(FileRefresher writer, String file, int level) {
        this(LFormatter.getFormatter(), writer, file, level);
    }
    public FileLogger(Formatter formatter, FileRefresher writer, String file, int level) {
        super(level, formatter);
        this.writer = writer;
        this.file = file;
    }
    protected void setFile(String file) {
        this.file = file;
    }
    @Override
    public void println(String tag, String message, String levelName) {
        writer.enQueue(file, new Date(), Thread.currentThread().getName(), levelName, tag, message);
    }
}
